
console.log(localStorage['lstore']);
chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
	console.log(request);
	if (request.name == 'load')
	{
		var ret = {name: 'lstore'};
		if(localStorage['lstore'] != null && localStorage['lstore'] != '' &&
			localStorage['lstore'].length != 0)
			ret = $.parseJSON(localStorage['lstore']);
		sendResponse(ret);
	}
	else if (request.name == 'commit')
	{
		console.log(stringify(request.data));
		localStorage['lstore'] = stringify(request.data);
	}
  });
  
function stringify (obj) {
    var t = typeof (obj);
    if (t != "object" || obj === null) {
        // simple data type
        if (t == "string") obj = '"'+obj+'"';
        return String(obj);
    }
    else {
        // recurse array or object
        var n, v, json = [], arr = (obj && obj.constructor == Array);
        for (n in obj) {
            v = obj[n]; t = typeof(v);
            if (t == "string") v = '"'+v+'"';
            else if (t == "object" && v !== null) v = stringify(v);
            json.push((arr ? "" : '"' + n + '":') + String(v));
        }
        return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
    }
}